package com.lx.patterns.factory.config_factory;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @ClassName CoffceFactory
 * @Description: //todo
 * @Author: 落雪
 * @CreateDate: 2025/1/14 22:29
 * @UpdateUser: 落雪
 * @UpdateDate: 2025/1/14 22:29
 * @UpdateRemark:
 * @Version: 1.0
 */
public class CoffeeFactory {

    private static Map<String,Coffee> map;

    static {
//        map = new HashMap<>();
        Properties p = new Properties();

        InputStream ins = CoffeeFactory.class.getClassLoader().getResourceAsStream("bean.properties");

        try {
            p.load(ins);
            Set<Object> keys = p.keySet();

            for(Object key  : keys){
                String className = p.getProperty((String) key);
                Class clazz = Class.forName(className);
                Coffee coffee = (Coffee) clazz.newInstance();
                map.put((String) key,coffee);
            }

        }catch (Exception e){

            e.printStackTrace();
        }


    }

    public static Coffee  createCoffee(String type){
        return map.get(type);
    }
}
